const form = document.querySelector("form");
/**@type {HTMLInputElement} username */
const username = document.getElementById("username");
const p = document.querySelectorAll("p")[1];

form.onsubmit = function (e) {
    console.log(e);
    if (username.value === "") {
        e.preventDefault();  //阻止默认行为，取消事件影响
        p.textContent = "用户名不能为空";
    }
}